package controller.teacher.manager.score;

import java.io.IOException;
import java.math.BigDecimal;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.annotation.WebServlet;

import controller.score.Base;

import dao.Score;

@WebServlet("/teacher/manager/score/del")
public class del extends Base {
    private static final long serialVersionUID = 1L;

    public del() {
        super();
    }

    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        try {
            Score.deleteById(new Integer(request.getParameter("id")));
            view.sendRedirect(
                    request.getContextPath() + "/teacher/manager/score?id="
                    + request.getParameter("stud"));
        } catch (NumberFormatException | SQLException e) {
            e.printStackTrace();
        }
    }

    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        try {
            Long stud = new Long(request.getParameter("stud"));
            String subject = request.getParameter("subject");
            BigDecimal score = new BigDecimal(request.getParameter("score"));
            Score.insert(stud, subject, score);
            view.sendRedirect(request.getContextPath() + "/teacher/manager/score?id="+stud);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

